#ifndef __Ray2_H_
#define __Ray2_H_


#include "U2PreRequest.h"
#include "U2Vector2.h"


U2EG_NAMESPACE_BEGIN


/** Representation of a ray in space, i.e. a line with an origin and direction. */
class _U2Share U2Ray2
{
protected:
    U2Vector2 mOrigin;
    U2Vector2 mDirection;

public:
    U2Ray2()
        : mOrigin(U2Vector2::ZERO)
        , mDirection(U2Vector2::UNIT_X)
    {

    }
    U2Ray2(const U2Vector2& origin, const U2Vector2& direction)
        : mOrigin(origin)
        , mDirection(direction)
    {

    }

    /** Sets the origin of the ray. */
    void setOrigin(const U2Vector2& origin) {mOrigin = origin;} 
    /** Gets the origin of the ray. */
    const U2Vector2& getOrigin(void) const {return mOrigin;} 

    /** Sets the direction of the ray. */
    void setDirection(const U2Vector2& dir) {mDirection = dir;} 
    /** Gets the direction of the ray. */
    const U2Vector2& getDirection(void) const {return mDirection;} 

	/** Gets the position of a point t units along the ray. */
	U2Vector2 getPoint(u2real t) const { 
		return U2Vector2(mOrigin + (mDirection * t));
	}
	
	U2Vector2 operator*(u2real t) const { 
		return getPoint(t);
	}

	/** Tests whether this ray intersects the given plane. 
	@returns A pair structure where the first element indicates whether
		an intersection occurs, and if true, the second element will
		indicate the distance along the ray at which it intersects. 
		This can be converted to a point in space by calling getPoint().
	*/
    /**********************@@@@@@@@@@@@@@@@@@@@@
	std::pair<bool, u2real> intersects(const Plane& p) const
	{
		return Math::intersects(*this, p);
	}
    */
    /** Tests whether this ray intersects the given plane bounded volume. 
    @returns A pair structure where the first element indicates whether
    an intersection occurs, and if true, the second element will
    indicate the distance along the ray at which it intersects. 
    This can be converted to a point in space by calling getPoint().
    */
    /**********************@@@@@@@@@@@@@@@@@@@@@
    std::pair<bool, u2real> intersects(const PlaneBoundedVolume& p) const
    {
        return Math::intersects(*this, p.planes, p.outside == Plane::POSITIVE_SIDE);
    }
    */
	/** Tests whether this ray intersects the given sphere. 
	@returns A pair structure where the first element indicates whether
		an intersection occurs, and if true, the second element will
		indicate the distance along the ray at which it intersects. 
		This can be converted to a point in space by calling getPoint().
	*/
    /**********************@@@@@@@@@@@@@@@@@@@@@
	std::pair<bool, u2real> intersects(const Sphere& s) const
	{
		return Math::intersects(*this, s);
	}
    */
	/** Tests whether this ray intersects the given box. 
	@returns A pair structure where the first element indicates whether
		an intersection occurs, and if true, the second element will
		indicate the distance along the ray at which it intersects. 
		This can be converted to a point in space by calling getPoint().
	*/
    /**********************@@@@@@@@@@@@@@@@@@@@@
	std::pair<bool, u2real> intersects(const AxisAlignedBox& box) const
	{
		return Math::intersects(*this, box);
	}
    */
};


U2EG_NAMESPACE_END


#endif
